<?php

namespace App\Http\Controllers\Exm;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Repositories\Eloquent\Exm\WarehouseRepository as Warehouse;
use App\Repositories\Eloquent\Exm\QuestionRepository as Question;
/**
 * Class LoginController
 * @package App\Http\Backend\Controllers
 */
class QuestionController extends Controller
{
    /**
     * @var Administrator
     */
    protected $warehouse, $question;

    public function __construct(Warehouse $warehouse, Question $question)
    {
        parent::__construct();

        $this->warehouse = $warehouse;

        $this->question = $question;
    }


    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        //儿童题型
        /*$qtype0 = $this->question->index(0)->get();  

        //成人题型
        $qtype1 = $this->question->index(1)->get();

        return view($this->view, compact('qtype0','qtype1'));*/

        $questions = $this->question->index()->get();
        
        return view($this->view, compact('questions'));
    }
    

    public function create()
    {
        return view($this->view);
    }


    public function store(Request $request)
    {
        return $this->question->store($request);
    }


    public function edit($id)
    {
        $question = $this->question->show($id);

        if ($question instanceof JsonResponse && $question->getStatusCode() === 404) {
            return abort('404');
        }

        return view($this->view, compact('question'));
    }
    

    public function update(Request $request, $id)
    {
        return $this->question->renew($request, $id);
    }

}
